package mainpackage;

public class Info {
	// private char gender;
	// private int status;
	// private String colour;
	// private String code;

	public char getGender(String infoCode) {
		return infoCode.charAt(0);
	}

	public int getStatus(String infoCode) {
		return Integer.parseInt(infoCode.substring(6, 7));
	}

	public String getColour(String infoCode) {
		String colour = infoCode.substring(4, 6);
		switch (colour) {
		case "BL":
			colour = Colour.BL.getColour();
			break;
		case "BN":
			colour = Colour.BN.getColour();
			break;
		case "BZ":
			colour = Colour.BZ.getColour();
			break;
		case "GD":
			colour = Colour.GD.getColour();
			break;
		case "GN":
			colour = Colour.GN.getColour();
			break;
		default:
			System.out.println("The value of colour is wrong");
			colour = null;
			break;
		}

		return colour;
	}

	public String getDragonCode(String infoCode) {
		return infoCode.substring(1, 4);
	}

	public int getHours(String infoCode) {
		return Integer.parseInt(infoCode.substring(7));
	}

	public String updateStatus(String infoCode, int newStatus) {
		String newInfoCode = infoCode.replace(infoCode.substring(6, 7),
				String.valueOf(newStatus));
		return newInfoCode;
	}

	public String resetHours(String infoCode) {
		String newInfoCode = infoCode.replace(infoCode.substring(7), "00");
		return newInfoCode;
	}

	public String updateHours(String infoCode, int addHours) {
		int originalHours = Integer.parseInt(infoCode.substring(7));
		int totalHours = originalHours + addHours;
		String newInfoCode;
		if (totalHours > 99) {
			newInfoCode = resetHours(infoCode);
			newInfoCode = updateStatus(newInfoCode, 3);
			return newInfoCode;
		} else {
			newInfoCode = infoCode.replace(infoCode.substring(7),
					String.valueOf(totalHours));
			return newInfoCode;
		}
	}

}
